package it.sd.pwframework.business.bean;

import java.util.Collections;
import java.util.LinkedList;

public class PwForm {

	private String id;
	
	private String label;
	
	private String classname;
	
	private String keyname;
	
	private LinkedList<PwProperty> properties = new LinkedList<PwProperty>();

	public String getClassname() {
		return classname;
	}
	public void setClassname(String classname) {
		this.classname = classname;
	}
	public LinkedList<PwProperty> getProperties() {
		return properties;
	}
	public void setProperties(LinkedList<PwProperty> properties) {
		this.properties = properties;
	}
	public String getKeyname() {
		return keyname;
	}
	public void setKeyname(String keyname) {
		this.keyname = keyname;
	}

	public void sort() {
		
		Collections.sort(properties);
		
		boolean found = false;
		for (PwProperty p : properties) {
			if (p.getSearcheable()) {
				found = true;
				break;
			}
		}
		if (!found) {
			properties.getFirst().setSearcheable(true);
		}
		
	}
	public String getLabel() {
		return label;
	}
	public void setLabel(String label) {
		this.label = label;
	}
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((classname == null) ? 0 : classname.hashCode());
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + ((keyname == null) ? 0 : keyname.hashCode());
		result = prime * result + ((label == null) ? 0 : label.hashCode());
		result = prime * result
				+ ((properties == null) ? 0 : properties.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		PwForm other = (PwForm) obj;
		if (classname == null) {
			if (other.classname != null)
				return false;
		} else if (!classname.equals(other.classname))
			return false;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (keyname == null) {
			if (other.keyname != null)
				return false;
		} else if (!keyname.equals(other.keyname))
			return false;
		if (label == null) {
			if (other.label != null)
				return false;
		} else if (!label.equals(other.label))
			return false;
		if (properties == null) {
			if (other.properties != null)
				return false;
		} else if (!properties.equals(other.properties))
			return false;
		return true;
	}
	@Override
	public String toString() {
		return "PwForm [id=" + id + ", label=" + label + ", classname="
				+ classname + ", keyname=" + keyname + ", properties="
				+ properties + "]";
	}
	
	
	
}
